package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.CurrentUser;
import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.vo.request.ExamStartVo;
import com.zhijian.medical.entity.vo.request.ExamWarehouseStudySaveOrUpdateVo;
import com.zhijian.medical.entity.vo.response.ExamDoingVo;
import com.zhijian.medical.entity.vo.response.ExamWarehouseStudyVo;
import com.zhijian.medical.service.ExamWarehouseStudyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 学习模块-题库关联关系表 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-04-01 15:01:57
 */
@Slf4j
@Controller
@Api(tags = "学习模块-题库关联关系表")
public class ExamWarehouseStudyController {

    @Autowired
    private ExamWarehouseStudyService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/exam/warehouse/study")
    @ApiOperation("新增")
    public boolean insert(@RequestBody ExamWarehouseStudySaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.insert(param) != null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/exam/warehouse/study/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/exam/warehouse/study/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody ExamWarehouseStudySaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据学习模块id查询
     *
     * @param studyId
     * @return
     */
    @Response
    @GetMapping("/exam/warehouse/study/{studyId}")
    @ApiOperation("根据学习模块id查询")
    public ExamWarehouseStudyVo selectById(@ApiParam(name = "studyId", value = "学习模块id")
                                           @PathVariable("studyId") Long studyId) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), studyId);
        return service.selectVoByStudyId(studyId);
    }

    /**
     * 开始考核
     *
     * @return
     */
    @Response
    @PostMapping("/exam/start")
    @ApiOperation("开始考核")
    public ExamDoingVo start(@CurrentUser @ApiIgnore PersonDto personDto, @RequestBody ExamStartVo param) {
        param.setUserId(personDto.getId());
        return service.start(param);
    }

}